package editar;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CadastroNotaFiscal2.java
 *
 * Created on 05/04/2011, 03:17:11
 */
import Classe.BD;
import Classe.Cliente;
import Classe.ClientePJ;
import Classe.Fornecedor;
import Classe.NotaFiscal;
import Classe.NotaHasPeca;
import Classe.Peca;
import Classe.Validacao;
import java.awt.Component;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import localizarInserir.LocalizarClienteInserir;
import localizarInserir.LocalizarClienteJuridicoInserir;
import localizarInserir.LocalizarFornecedorInseir;
import localizarInserir.LocalizarPecaInserir;

/**
 *
 * @author gladson
 */
public class EditarNotaFiscal extends Validacao {

    private Component frameI;

    /** Creates new form CadastroNotaFiscal2 */
    public EditarNotaFiscal() {
        initComponents();
        this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        iniciar();
    }
    Cliente cli = new Cliente();
    ClientePJ clipj = new ClientePJ();
    Fornecedor forn = new Fornecedor();
    NotaFiscal nf = new NotaFiscal();
    int opc = 0;
    Double precoTotalPeca;
    Double valorTotNota;
    int tipocliente;

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        pnlCadastroNotaFiscal = new javax.swing.JPanel();
        jTabbedPaneNF = new javax.swing.JTabbedPane();
        pnlDestinatarioRemetente = new javax.swing.JPanel();
        pnlNaturezaOperacao = new javax.swing.JPanel();
        lblNaturezaOperacaoNotaFiscal = new javax.swing.JLabel();
        lblDataEmissaoNotaFiscal = new javax.swing.JLabel();
        lblDataEntradaSaidaNotaFiscal = new javax.swing.JLabel();
        lblHoraSaidaNotaFiscal = new javax.swing.JLabel();
        jTextField35 = new javax.swing.JTextField();
        cbNaturezaOperacao = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        cbTipoNota = new javax.swing.JComboBox();
        sTxtDataSaidaEntrada = new javax.swing.JFormattedTextField();
        sTxtDataEmissao = new javax.swing.JFormattedTextField();
        sTxtHoraSaidaNotaFiscal = new javax.swing.JFormattedTextField();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        pnlDestinatarioRemetenteNotaFiscal = new javax.swing.JPanel();
        rdPessoaFisicaNotaFiscal = new javax.swing.JRadioButton();
        rdPessoaJuridicaNotaFiscal = new javax.swing.JRadioButton();
        lblNomeRazaoNotaFiscal = new javax.swing.JLabel();
        lblCnpjCpfNotaFiscal = new javax.swing.JLabel();
        lblIncricaoEstadualNotaFiscal = new javax.swing.JLabel();
        sTxtNomeRazaoSocialNotaFiscal = new javax.swing.JTextField();
        sTxtCnpjCpfNotaFiscal = new javax.swing.JFormattedTextField();
        sTxtIncricaoEstadualNotaFiscal = new javax.swing.JTextField();
        lblTelefoneFaxNotaFiscal = new javax.swing.JLabel();
        sTxtTelefoneFaxNotaFiscal = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        stxtAreaNotaFiscal = new javax.swing.JTextArea();
        jLabel8 = new javax.swing.JLabel();
        pnlEnderecoNotaFiscal = new javax.swing.JPanel();
        lblRuaAvenidaNotaFiscal = new javax.swing.JLabel();
        iTxtNumeroCliente = new javax.swing.JTextField();
        lblNumeroNotaFiscal = new javax.swing.JLabel();
        lblBairroNotaFiscal = new javax.swing.JLabel();
        lblCidadeNotaFiscal = new javax.swing.JLabel();
        lblUfNotaFiscal = new javax.swing.JLabel();
        lblApSalaNotaFiscal = new javax.swing.JLabel();
        stxtApSalaCliente = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        stxtCEPCliente = new javax.swing.JTextField();
        TxtComplCliente = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        cbUfCliente = new javax.swing.JTextField();
        cbCidadeCliente = new javax.swing.JTextField();
        cbBairroCliente = new javax.swing.JTextField();
        txtEndCliente = new javax.swing.JTextField();
        pnlPecaNotaFilcal = new javax.swing.JPanel();
        pnlProdutoPeca = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tabelaPecas = new javax.swing.JTable();
        btIncluirPeca = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        txtCodPeca = new javax.swing.JTextField();
        btExcluirPeca = new javax.swing.JButton();
        btLocPecaNF = new javax.swing.JButton();
        cbUniNF = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        txtQuantNF = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        txtValorUnitNF = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        pnlServNotaFilcal = new javax.swing.JPanel();
        pnlInternoServiçoNota = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        sTxtServicoNotaFiscal = new javax.swing.JTextArea();
        lblValorServicoNotaFiscal = new javax.swing.JLabel();
        txtValorServicoNotaFiscal = new javax.swing.JTextField();
        jButton3 = new javax.swing.JButton();
        btSairNotaFiscal = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setResizable(false);

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));

        pnlCadastroNotaFiscal.setBackground(new java.awt.Color(255, 255, 255));
        pnlCadastroNotaFiscal.setBorder(javax.swing.BorderFactory.createTitledBorder(null, " Editar Nota Fical ", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("PMingLiU", 0, 36))); // NOI18N
        pnlCadastroNotaFiscal.setPreferredSize(new java.awt.Dimension(800, 600));

        pnlDestinatarioRemetente.setBackground(new java.awt.Color(255, 255, 255));

        pnlNaturezaOperacao.setBackground(new java.awt.Color(255, 255, 255));
        pnlNaturezaOperacao.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        lblNaturezaOperacaoNotaFiscal.setFont(new java.awt.Font("Arial", 1, 11));
        lblNaturezaOperacaoNotaFiscal.setText("Natureza da Operação");

        lblDataEmissaoNotaFiscal.setFont(new java.awt.Font("Arial", 1, 11));
        lblDataEmissaoNotaFiscal.setText("Data Emissão:");

        lblDataEntradaSaidaNotaFiscal.setFont(new java.awt.Font("Arial", 1, 11));
        lblDataEntradaSaidaNotaFiscal.setText("Data Saída/Entrada:");

        lblHoraSaidaNotaFiscal.setFont(new java.awt.Font("Arial", 1, 11));
        lblHoraSaidaNotaFiscal.setText("Hora da Saída");

        jTextField35.setText("jTextField15");

        cbNaturezaOperacao.setModel(new javax.swing.DefaultComboBoxModel(new String[] {
            "",
            "COMPRA",
            "VENDA",
            "MANUTENÇÃO" }));
cbNaturezaOperacao.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

jLabel1.setFont(new java.awt.Font("Arial", 1, 11));
jLabel1.setText("Tipo de Nota");

cbTipoNota.setModel(new javax.swing.DefaultComboBoxModel(new String[] {
    "", "ENTRADA", "SAIDA"}));
    cbTipoNota.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

    sTxtDataSaidaEntrada.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
    try {
        sTxtDataSaidaEntrada.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##/##/####")));
    } catch (java.text.ParseException ex) {
        ex.printStackTrace();
    }

    sTxtDataEmissao.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
    try {
        sTxtDataEmissao.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##/##/####")));
    } catch (java.text.ParseException ex) {
        ex.printStackTrace();
    }

    sTxtHoraSaidaNotaFiscal.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
    try {
        sTxtHoraSaidaNotaFiscal.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##:##:##")));
    } catch (java.text.ParseException ex) {
        ex.printStackTrace();
    }

    jButton1.setText("CLIENTE PF");
    jButton1.setToolTipText("Incluir Cliente");
    jButton1.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED), javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)));
    jButton1.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButton1ActionPerformed(evt);
        }
    });

    jButton2.setText("CLIENTE PJ");
    jButton2.setToolTipText("Incluir Cliente Jurídico");
    jButton2.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED), javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)));
    jButton2.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButton2ActionPerformed(evt);
        }
    });

    jButton4.setText("FORNECEDOR");
    jButton4.setToolTipText("Incluir Fornecedor");
    jButton4.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED), javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)));
    jButton4.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButton4ActionPerformed(evt);
        }
    });

    javax.swing.GroupLayout pnlNaturezaOperacaoLayout = new javax.swing.GroupLayout(pnlNaturezaOperacao);
    pnlNaturezaOperacao.setLayout(pnlNaturezaOperacaoLayout);
    pnlNaturezaOperacaoLayout.setHorizontalGroup(
        pnlNaturezaOperacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(pnlNaturezaOperacaoLayout.createSequentialGroup()
            .addContainerGap()
            .addGroup(pnlNaturezaOperacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(pnlNaturezaOperacaoLayout.createSequentialGroup()
                    .addGroup(pnlNaturezaOperacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(cbTipoNota, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel1))
                    .addGap(18, 18, 18)
                    .addGroup(pnlNaturezaOperacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(cbNaturezaOperacao, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(lblNaturezaOperacaoNotaFiscal))
                    .addGap(18, 18, 18)
                    .addGroup(pnlNaturezaOperacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(sTxtDataEmissao, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(lblDataEmissaoNotaFiscal))
                    .addGap(18, 18, 18)
                    .addGroup(pnlNaturezaOperacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(sTxtDataSaidaEntrada, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(lblDataEntradaSaidaNotaFiscal))
                    .addGap(18, 18, 18)
                    .addGroup(pnlNaturezaOperacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(lblHoraSaidaNotaFiscal)
                        .addComponent(sTxtHoraSaidaNotaFiscal, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGroup(pnlNaturezaOperacaoLayout.createSequentialGroup()
                    .addComponent(jButton1)
                    .addGap(202, 202, 202)
                    .addComponent(jButton2)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 278, Short.MAX_VALUE)
                    .addComponent(jButton4)))
            .addContainerGap())
    );

    pnlNaturezaOperacaoLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jButton1, jButton2, jButton4});

    pnlNaturezaOperacaoLayout.setVerticalGroup(
        pnlNaturezaOperacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlNaturezaOperacaoLayout.createSequentialGroup()
            .addContainerGap()
            .addGroup(pnlNaturezaOperacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                .addGroup(pnlNaturezaOperacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton2)
                    .addComponent(jButton4))
                .addComponent(jButton1))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 10, Short.MAX_VALUE)
            .addGroup(pnlNaturezaOperacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                .addGroup(pnlNaturezaOperacaoLayout.createSequentialGroup()
                    .addComponent(jLabel1)
                    .addGap(26, 26, 26))
                .addComponent(cbTipoNota, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(cbNaturezaOperacao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(pnlNaturezaOperacaoLayout.createSequentialGroup()
                    .addGroup(pnlNaturezaOperacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(lblDataEmissaoNotaFiscal)
                        .addComponent(lblNaturezaOperacaoNotaFiscal, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(sTxtDataEmissao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlNaturezaOperacaoLayout.createSequentialGroup()
            .addContainerGap()
            .addComponent(lblDataEntradaSaidaNotaFiscal)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(sTxtDataSaidaEntrada, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlNaturezaOperacaoLayout.createSequentialGroup()
            .addGap(41, 41, 41)
            .addComponent(lblHoraSaidaNotaFiscal)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(sTxtHoraSaidaNotaFiscal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
    );

    pnlNaturezaOperacaoLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jButton1, jButton2, jButton4});

    pnlDestinatarioRemetenteNotaFiscal.setBackground(new java.awt.Color(255, 255, 255));
    pnlDestinatarioRemetenteNotaFiscal.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Destinatário/Remetente", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12))); // NOI18N

    buttonGroup1.add(rdPessoaFisicaNotaFiscal);
    rdPessoaFisicaNotaFiscal.setText("Pessoa Fisca");

    buttonGroup1.add(rdPessoaJuridicaNotaFiscal);
    rdPessoaJuridicaNotaFiscal.setText("Pessoa Jurídica");

    lblNomeRazaoNotaFiscal.setFont(new java.awt.Font("Arial", 1, 11));
    lblNomeRazaoNotaFiscal.setText("Nome/Razão Social");

    lblCnpjCpfNotaFiscal.setFont(new java.awt.Font("Arial", 1, 11));
    lblCnpjCpfNotaFiscal.setText("CNPJ/CPF:");

    lblIncricaoEstadualNotaFiscal.setFont(new java.awt.Font("Arial", 1, 11));
    lblIncricaoEstadualNotaFiscal.setText("Insc.Estaual: ");

    sTxtNomeRazaoSocialNotaFiscal.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

    sTxtCnpjCpfNotaFiscal.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

    sTxtIncricaoEstadualNotaFiscal.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

    lblTelefoneFaxNotaFiscal.setFont(new java.awt.Font("Arial", 1, 11));
    lblTelefoneFaxNotaFiscal.setText("Tel/Fax");

    sTxtTelefoneFaxNotaFiscal.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

    javax.swing.GroupLayout pnlDestinatarioRemetenteNotaFiscalLayout = new javax.swing.GroupLayout(pnlDestinatarioRemetenteNotaFiscal);
    pnlDestinatarioRemetenteNotaFiscal.setLayout(pnlDestinatarioRemetenteNotaFiscalLayout);
    pnlDestinatarioRemetenteNotaFiscalLayout.setHorizontalGroup(
        pnlDestinatarioRemetenteNotaFiscalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(pnlDestinatarioRemetenteNotaFiscalLayout.createSequentialGroup()
            .addContainerGap()
            .addGroup(pnlDestinatarioRemetenteNotaFiscalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(pnlDestinatarioRemetenteNotaFiscalLayout.createSequentialGroup()
                    .addGroup(pnlDestinatarioRemetenteNotaFiscalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(lblNomeRazaoNotaFiscal)
                        .addComponent(sTxtNomeRazaoSocialNotaFiscal, javax.swing.GroupLayout.PREFERRED_SIZE, 304, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(pnlDestinatarioRemetenteNotaFiscalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(lblCnpjCpfNotaFiscal)
                        .addComponent(sTxtCnpjCpfNotaFiscal, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(pnlDestinatarioRemetenteNotaFiscalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(lblIncricaoEstadualNotaFiscal)
                        .addComponent(sTxtIncricaoEstadualNotaFiscal, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(14, 14, 14)
                    .addGroup(pnlDestinatarioRemetenteNotaFiscalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(sTxtTelefoneFaxNotaFiscal, javax.swing.GroupLayout.DEFAULT_SIZE, 98, Short.MAX_VALUE)
                        .addComponent(lblTelefoneFaxNotaFiscal)))
                .addGroup(pnlDestinatarioRemetenteNotaFiscalLayout.createSequentialGroup()
                    .addComponent(rdPessoaFisicaNotaFiscal)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(rdPessoaJuridicaNotaFiscal)))
            .addContainerGap())
    );
    pnlDestinatarioRemetenteNotaFiscalLayout.setVerticalGroup(
        pnlDestinatarioRemetenteNotaFiscalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(pnlDestinatarioRemetenteNotaFiscalLayout.createSequentialGroup()
            .addGroup(pnlDestinatarioRemetenteNotaFiscalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                .addGroup(pnlDestinatarioRemetenteNotaFiscalLayout.createSequentialGroup()
                    .addComponent(lblCnpjCpfNotaFiscal)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(sTxtCnpjCpfNotaFiscal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(pnlDestinatarioRemetenteNotaFiscalLayout.createSequentialGroup()
                    .addComponent(lblIncricaoEstadualNotaFiscal)
                    .addGap(26, 26, 26))
                .addGroup(pnlDestinatarioRemetenteNotaFiscalLayout.createSequentialGroup()
                    .addComponent(lblTelefoneFaxNotaFiscal)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(pnlDestinatarioRemetenteNotaFiscalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(sTxtIncricaoEstadualNotaFiscal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(sTxtTelefoneFaxNotaFiscal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGroup(pnlDestinatarioRemetenteNotaFiscalLayout.createSequentialGroup()
                    .addGroup(pnlDestinatarioRemetenteNotaFiscalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(rdPessoaFisicaNotaFiscal)
                        .addComponent(rdPessoaJuridicaNotaFiscal))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(lblNomeRazaoNotaFiscal)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(sTxtNomeRazaoSocialNotaFiscal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );

    stxtAreaNotaFiscal.setColumns(20);
    stxtAreaNotaFiscal.setRows(5);
    stxtAreaNotaFiscal.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
    jScrollPane1.setViewportView(stxtAreaNotaFiscal);

    jLabel8.setFont(new java.awt.Font("Arial", 1, 11));
    jLabel8.setText("Observação");

    pnlEnderecoNotaFiscal.setBackground(new java.awt.Color(255, 255, 255));
    pnlEnderecoNotaFiscal.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Endereço", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12))); // NOI18N

    lblRuaAvenidaNotaFiscal.setFont(new java.awt.Font("Arial", 1, 11));
    lblRuaAvenidaNotaFiscal.setText("Rua/Av.");

    iTxtNumeroCliente.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

    lblNumeroNotaFiscal.setFont(new java.awt.Font("Arial", 1, 11));
    lblNumeroNotaFiscal.setText("Nº.:");

    lblBairroNotaFiscal.setFont(new java.awt.Font("Arial", 1, 11));
    lblBairroNotaFiscal.setText("Bairro");

    lblCidadeNotaFiscal.setFont(new java.awt.Font("Arial", 1, 11));
    lblCidadeNotaFiscal.setText("Cidade");

    lblUfNotaFiscal.setFont(new java.awt.Font("Arial", 1, 11));
    lblUfNotaFiscal.setText("UF");

    lblApSalaNotaFiscal.setFont(new java.awt.Font("Arial", 1, 11));
    lblApSalaNotaFiscal.setText("Ap/Sala");

    stxtApSalaCliente.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

    jLabel2.setFont(new java.awt.Font("Arial", 1, 11));
    jLabel2.setText("CEP");

    stxtCEPCliente.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

    TxtComplCliente.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

    jLabel3.setFont(new java.awt.Font("Arial", 1, 11));
    jLabel3.setText("Complemento");

    cbUfCliente.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

    cbCidadeCliente.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

    cbBairroCliente.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

    txtEndCliente.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

    javax.swing.GroupLayout pnlEnderecoNotaFiscalLayout = new javax.swing.GroupLayout(pnlEnderecoNotaFiscal);
    pnlEnderecoNotaFiscal.setLayout(pnlEnderecoNotaFiscalLayout);
    pnlEnderecoNotaFiscalLayout.setHorizontalGroup(
        pnlEnderecoNotaFiscalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(pnlEnderecoNotaFiscalLayout.createSequentialGroup()
            .addContainerGap()
            .addGroup(pnlEnderecoNotaFiscalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(pnlEnderecoNotaFiscalLayout.createSequentialGroup()
                    .addGroup(pnlEnderecoNotaFiscalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(lblUfNotaFiscal)
                        .addGroup(pnlEnderecoNotaFiscalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(cbUfCliente, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblRuaAvenidaNotaFiscal, javax.swing.GroupLayout.Alignment.LEADING)))
                    .addGap(18, 18, 18)
                    .addGroup(pnlEnderecoNotaFiscalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(cbCidadeCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 263, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(lblCidadeNotaFiscal)))
                .addComponent(txtEndCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 354, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(pnlEnderecoNotaFiscalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(lblBairroNotaFiscal)
                .addGroup(pnlEnderecoNotaFiscalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(pnlEnderecoNotaFiscalLayout.createSequentialGroup()
                        .addGroup(pnlEnderecoNotaFiscalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addComponent(TxtComplCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 154, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(pnlEnderecoNotaFiscalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblNumeroNotaFiscal)
                            .addComponent(iTxtNumeroCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(cbBairroCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 259, javax.swing.GroupLayout.PREFERRED_SIZE)))
            .addGap(18, 18, 18)
            .addGroup(pnlEnderecoNotaFiscalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                .addComponent(lblApSalaNotaFiscal)
                .addComponent(stxtApSalaCliente, javax.swing.GroupLayout.DEFAULT_SIZE, 70, Short.MAX_VALUE)
                .addComponent(jLabel2)
                .addComponent(stxtCEPCliente))
            .addContainerGap(14, Short.MAX_VALUE))
    );
    pnlEnderecoNotaFiscalLayout.setVerticalGroup(
        pnlEnderecoNotaFiscalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(pnlEnderecoNotaFiscalLayout.createSequentialGroup()
            .addGroup(pnlEnderecoNotaFiscalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlEnderecoNotaFiscalLayout.createSequentialGroup()
                    .addComponent(jLabel2)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(stxtCEPCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(6, 6, 6))
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlEnderecoNotaFiscalLayout.createSequentialGroup()
                    .addComponent(lblBairroNotaFiscal)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(cbBairroCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlEnderecoNotaFiscalLayout.createSequentialGroup()
                    .addComponent(lblUfNotaFiscal)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(cbUfCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlEnderecoNotaFiscalLayout.createSequentialGroup()
                    .addComponent(lblCidadeNotaFiscal)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(cbCidadeCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
            .addGroup(pnlEnderecoNotaFiscalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(pnlEnderecoNotaFiscalLayout.createSequentialGroup()
                    .addComponent(lblApSalaNotaFiscal)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(stxtApSalaCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(pnlEnderecoNotaFiscalLayout.createSequentialGroup()
                    .addComponent(lblRuaAvenidaNotaFiscal)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(txtEndCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(pnlEnderecoNotaFiscalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(TxtComplCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(pnlEnderecoNotaFiscalLayout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addGap(26, 26, 26))
                    .addGroup(pnlEnderecoNotaFiscalLayout.createSequentialGroup()
                        .addComponent(lblNumeroNotaFiscal)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(iTxtNumeroCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );

    javax.swing.GroupLayout pnlDestinatarioRemetenteLayout = new javax.swing.GroupLayout(pnlDestinatarioRemetente);
    pnlDestinatarioRemetente.setLayout(pnlDestinatarioRemetenteLayout);
    pnlDestinatarioRemetenteLayout.setHorizontalGroup(
        pnlDestinatarioRemetenteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlDestinatarioRemetenteLayout.createSequentialGroup()
            .addContainerGap()
            .addGroup(pnlDestinatarioRemetenteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jLabel8)
                .addComponent(pnlNaturezaOperacao, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(pnlDestinatarioRemetenteNotaFiscal, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 743, Short.MAX_VALUE)
                .addComponent(pnlEnderecoNotaFiscal, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addContainerGap())
    );
    pnlDestinatarioRemetenteLayout.setVerticalGroup(
        pnlDestinatarioRemetenteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(pnlDestinatarioRemetenteLayout.createSequentialGroup()
            .addContainerGap()
            .addComponent(pnlNaturezaOperacao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(pnlDestinatarioRemetenteNotaFiscal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(pnlEnderecoNotaFiscal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGap(1, 1, 1)
            .addComponent(jLabel8)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 97, Short.MAX_VALUE)
            .addContainerGap())
    );

    jTabbedPaneNF.addTab("Destinatário/Remetente", pnlDestinatarioRemetente);

    pnlPecaNotaFilcal.setBackground(new java.awt.Color(255, 255, 255));

    pnlProdutoPeca.setBackground(new java.awt.Color(255, 255, 255));
    pnlProdutoPeca.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Produto(s)", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12))); // NOI18N
    pnlProdutoPeca.setPreferredSize(new java.awt.Dimension(718, 450));

    tabelaPecas.setModel(new javax.swing.table.DefaultTableModel(
        new Object [][] {

        },
        new String [] {
            "Código", "Descrição dos Produtos", "Unid.", "Quant.", "valor unit", "Valor Total"
        }
    ) {
        Class[] types = new Class [] {
            java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.Double.class, java.lang.Double.class, java.lang.Double.class
        };
        boolean[] canEdit = new boolean [] {
            false, false, false, false, false, false
        };

        public Class getColumnClass(int columnIndex) {
            return types [columnIndex];
        }

        public boolean isCellEditable(int rowIndex, int columnIndex) {
            return canEdit [columnIndex];
        }
    });
    jScrollPane2.setViewportView(tabelaPecas);
    tabelaPecas.getColumnModel().getColumn(0).setPreferredWidth(20);
    tabelaPecas.getColumnModel().getColumn(1).setPreferredWidth(262);
    tabelaPecas.getColumnModel().getColumn(2).setPreferredWidth(3);
    tabelaPecas.getColumnModel().getColumn(3).setPreferredWidth(20);
    tabelaPecas.getColumnModel().getColumn(4).setPreferredWidth(35);
    tabelaPecas.getColumnModel().getColumn(5).setPreferredWidth(35);

    btIncluirPeca.setFont(new java.awt.Font("Arial", 0, 12));
    btIncluirPeca.setText("Incluir");
    btIncluirPeca.setToolTipText("Incluir Peça");
    btIncluirPeca.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            btIncluirPecaActionPerformed(evt);
        }
    });

    jLabel4.setFont(new java.awt.Font("Arial", 1, 11));
    jLabel4.setText("Cód. Peça");

    txtCodPeca.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

    btExcluirPeca.setFont(new java.awt.Font("Arial", 0, 12));
    btExcluirPeca.setText("Excluir");
    btExcluirPeca.setToolTipText("Excluir Peça Selecionada");
    btExcluirPeca.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            btExcluirPecaActionPerformed(evt);
        }
    });

    btLocPecaNF.setText("Localizar Peça");
    btLocPecaNF.setToolTipText("Localizar Peça");
    btLocPecaNF.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            btLocPecaNFActionPerformed(evt);
        }
    });

    cbUniNF.setModel(new javax.swing.DefaultComboBoxModel(new String[] {
        "","CX","UNID.","PCTE","KG","GR"}));
cbUniNF.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

jLabel5.setFont(new java.awt.Font("Arial", 1, 11));
jLabel5.setText("Unidade");

txtQuantNF.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

jLabel6.setFont(new java.awt.Font("Arial", 1, 11));
jLabel6.setText("Quant.");

txtValorUnitNF.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

jLabel7.setFont(new java.awt.Font("Arial", 1, 11));
jLabel7.setText("Valor Unit.");

javax.swing.GroupLayout pnlProdutoPecaLayout = new javax.swing.GroupLayout(pnlProdutoPeca);
pnlProdutoPeca.setLayout(pnlProdutoPecaLayout);
pnlProdutoPecaLayout.setHorizontalGroup(
pnlProdutoPecaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlProdutoPecaLayout.createSequentialGroup()
    .addContainerGap()
    .addGroup(pnlProdutoPecaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 711, Short.MAX_VALUE)
        .addGroup(pnlProdutoPecaLayout.createSequentialGroup()
            .addGroup(pnlProdutoPecaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                .addGroup(pnlProdutoPecaLayout.createSequentialGroup()
                    .addComponent(jLabel4)
                    .addGap(47, 47, 47))
                .addGroup(pnlProdutoPecaLayout.createSequentialGroup()
                    .addComponent(txtCodPeca, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(18, 18, 18)))
            .addGroup(pnlProdutoPecaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jLabel5)
                .addComponent(cbUniNF, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGap(18, 18, 18)
            .addGroup(pnlProdutoPecaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jLabel6)
                .addComponent(txtQuantNF, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGap(18, 18, 18)
            .addGroup(pnlProdutoPecaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(pnlProdutoPecaLayout.createSequentialGroup()
                    .addComponent(txtValorUnitNF, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(18, 18, 18)
                    .addComponent(btIncluirPeca)
                    .addGap(18, 18, 18)
                    .addComponent(btExcluirPeca)
                    .addGap(18, 18, 18)
                    .addComponent(btLocPecaNF))
                .addComponent(jLabel7))))
    .addContainerGap())
    );

    pnlProdutoPecaLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {cbUniNF, txtCodPeca, txtQuantNF, txtValorUnitNF});

    pnlProdutoPecaLayout.setVerticalGroup(
        pnlProdutoPecaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlProdutoPecaLayout.createSequentialGroup()
            .addGap(11, 11, 11)
            .addGroup(pnlProdutoPecaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel6)
                .addComponent(jLabel7)
                .addComponent(jLabel4)
                .addComponent(jLabel5))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(pnlProdutoPecaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(txtCodPeca, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(cbUniNF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(txtQuantNF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(txtValorUnitNF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(btIncluirPeca)
                .addComponent(btExcluirPeca)
                .addComponent(btLocPecaNF))
            .addGap(18, 18, 18)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 356, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addContainerGap())
    );

    pnlProdutoPecaLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {btExcluirPeca, btIncluirPeca, btLocPecaNF});

    javax.swing.GroupLayout pnlPecaNotaFilcalLayout = new javax.swing.GroupLayout(pnlPecaNotaFilcal);
    pnlPecaNotaFilcal.setLayout(pnlPecaNotaFilcalLayout);
    pnlPecaNotaFilcalLayout.setHorizontalGroup(
        pnlPecaNotaFilcalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(pnlPecaNotaFilcalLayout.createSequentialGroup()
            .addContainerGap()
            .addComponent(pnlProdutoPeca, javax.swing.GroupLayout.DEFAULT_SIZE, 743, Short.MAX_VALUE)
            .addContainerGap())
    );
    pnlPecaNotaFilcalLayout.setVerticalGroup(
        pnlPecaNotaFilcalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(pnlPecaNotaFilcalLayout.createSequentialGroup()
            .addContainerGap()
            .addComponent(pnlProdutoPeca, javax.swing.GroupLayout.PREFERRED_SIZE, 467, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );

    jTabbedPaneNF.addTab("Peça", pnlPecaNotaFilcal);

    pnlServNotaFilcal.setBackground(new java.awt.Color(255, 255, 255));

    pnlInternoServiçoNota.setBackground(new java.awt.Color(255, 255, 255));
    pnlInternoServiçoNota.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Seviço(s)", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12))); // NOI18N

    sTxtServicoNotaFiscal.setColumns(20);
    sTxtServicoNotaFiscal.setRows(5);
    sTxtServicoNotaFiscal.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
    jScrollPane3.setViewportView(sTxtServicoNotaFiscal);

    lblValorServicoNotaFiscal.setFont(new java.awt.Font("Arial", 1, 11));
    lblValorServicoNotaFiscal.setText("Valor Serviço");

    txtValorServicoNotaFiscal.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

    javax.swing.GroupLayout pnlInternoServiçoNotaLayout = new javax.swing.GroupLayout(pnlInternoServiçoNota);
    pnlInternoServiçoNota.setLayout(pnlInternoServiçoNotaLayout);
    pnlInternoServiçoNotaLayout.setHorizontalGroup(
        pnlInternoServiçoNotaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(pnlInternoServiçoNotaLayout.createSequentialGroup()
            .addContainerGap()
            .addGroup(pnlInternoServiçoNotaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 711, Short.MAX_VALUE)
                .addComponent(lblValorServicoNotaFiscal)
                .addComponent(txtValorServicoNotaFiscal, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addContainerGap())
    );
    pnlInternoServiçoNotaLayout.setVerticalGroup(
        pnlInternoServiçoNotaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlInternoServiçoNotaLayout.createSequentialGroup()
            .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 189, Short.MAX_VALUE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
            .addComponent(lblValorServicoNotaFiscal)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(txtValorServicoNotaFiscal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addContainerGap())
    );

    javax.swing.GroupLayout pnlServNotaFilcalLayout = new javax.swing.GroupLayout(pnlServNotaFilcal);
    pnlServNotaFilcal.setLayout(pnlServNotaFilcalLayout);
    pnlServNotaFilcalLayout.setHorizontalGroup(
        pnlServNotaFilcalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(pnlServNotaFilcalLayout.createSequentialGroup()
            .addContainerGap()
            .addComponent(pnlInternoServiçoNota, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addContainerGap())
    );
    pnlServNotaFilcalLayout.setVerticalGroup(
        pnlServNotaFilcalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(pnlServNotaFilcalLayout.createSequentialGroup()
            .addContainerGap()
            .addComponent(pnlInternoServiçoNota, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGap(191, 191, 191))
    );

    jTabbedPaneNF.addTab("Serviço", pnlServNotaFilcal);

    jButton3.setText("Salvar");
    jButton3.setToolTipText("Salvar");
    jButton3.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED), javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)));
    jButton3.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButton3ActionPerformed(evt);
        }
    });

    btSairNotaFiscal.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
    btSairNotaFiscal.setText("Sair");
    btSairNotaFiscal.setToolTipText("Sair");
    btSairNotaFiscal.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED), javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)));
    btSairNotaFiscal.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            btSairNotaFiscalActionPerformed(evt);
        }
    });

    javax.swing.GroupLayout pnlCadastroNotaFiscalLayout = new javax.swing.GroupLayout(pnlCadastroNotaFiscal);
    pnlCadastroNotaFiscal.setLayout(pnlCadastroNotaFiscalLayout);
    pnlCadastroNotaFiscalLayout.setHorizontalGroup(
        pnlCadastroNotaFiscalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addComponent(jTabbedPaneNF, javax.swing.GroupLayout.DEFAULT_SIZE, 768, Short.MAX_VALUE)
        .addGroup(pnlCadastroNotaFiscalLayout.createSequentialGroup()
            .addContainerGap()
            .addComponent(jButton3)
            .addGap(18, 18, 18)
            .addComponent(btSairNotaFiscal)
            .addContainerGap(662, Short.MAX_VALUE))
    );

    pnlCadastroNotaFiscalLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btSairNotaFiscal, jButton3});

    pnlCadastroNotaFiscalLayout.setVerticalGroup(
        pnlCadastroNotaFiscalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(pnlCadastroNotaFiscalLayout.createSequentialGroup()
            .addComponent(jTabbedPaneNF, javax.swing.GroupLayout.PREFERRED_SIZE, 507, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(pnlCadastroNotaFiscalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jButton3)
                .addComponent(btSairNotaFiscal)))
    );

    pnlCadastroNotaFiscalLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {btSairNotaFiscal, jButton3});

    javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(
        jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel1Layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(pnlCadastroNotaFiscal, javax.swing.GroupLayout.DEFAULT_SIZE, 780, Short.MAX_VALUE)
            .addContainerGap())
    );
    jPanel1Layout.setVerticalGroup(
        jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel1Layout.createSequentialGroup()
            .addComponent(pnlCadastroNotaFiscal, javax.swing.GroupLayout.PREFERRED_SIZE, 587, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addContainerGap(13, Short.MAX_VALUE))
    );

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    );

    java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
    setBounds((screenSize.width-808)/2, (screenSize.height-627)/2, 808, 627);
    }// </editor-fold>//GEN-END:initComponents

    private void btSairNotaFiscalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btSairNotaFiscalActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_btSairNotaFiscalActionPerformed

    private void btIncluirPecaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btIncluirPecaActionPerformed
        if (validarPeca()) {
            try {
                int codPeca = Integer.parseInt(txtCodPeca.getText().trim());
                String sql = "SELECT * FROM PECA WHERE ID_PECA=" + codPeca;

                BD banco = new BD();
                ResultSet res = banco.consultar(sql);

                DefaultTableModel model = (DefaultTableModel) tabelaPecas.getModel();

                String unidade = (String) cbUniNF.getSelectedItem();
                int quantidade = Integer.parseInt(txtQuantNF.getText().trim());
                Double preco = Double.parseDouble(txtValorUnitNF.getText().trim());
                precoTotalPeca = preco * quantidade;

                if (res.next()) {
                    Object[] linha = {
                        res.getInt("ID_PECA"),
                        res.getString("NOME_PECA"),
                        unidade,
                        quantidade,
                        preco,
                        precoTotalPeca
                    };

                    model.addRow(linha);
                }
                txtCodPeca.setText("");
                cbUniNF.setSelectedItem("");
                txtQuantNF.setText("");
                txtValorUnitNF.setText("");

            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }//GEN-LAST:event_btIncluirPecaActionPerformed

    private void btLocPecaNFActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btLocPecaNFActionPerformed
        LocalizarPecaInserir locPecIns = new LocalizarPecaInserir();
        locPecIns.setVisible(true);
    }//GEN-LAST:event_btLocPecaNFActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed

        if (validar()) {

//////////////////////////SALVANDO A NOTA////////////////////////////////////////////////////////////////////////

            try {



                nf.setDataNotaFiscal(sTxtDataEmissao.getText().trim());//data_nf
//////////////////////////////PEGANDO O VALOR TOTAL DOS PRODUTOS////////////////////////////////////////////////
                DefaultTableModel tableModel = (DefaultTableModel) tabelaPecas.getModel();
                int linhas = tableModel.getRowCount();//contando quantas colunas tem
                double totalNf = 0;
                int i = 0;
                if (linhas > 0) {
                    while (i < linhas) {
                        Double test1 = Double.parseDouble(tableModel.getValueAt(i, 5).toString());
                        totalNf = totalNf + test1;
                        i++;
                    }
                }
///////////////////////////////FIM DE PEGANDO O VALOR TOTAL DOS PRODUTOS////////////////////////////////////////

                nf.setObservacaoNotaFiscal(stxtAreaNotaFiscal.getText().trim().toUpperCase());//observacao_nf
                nf.setTipoNotaFiscal((String) cbTipoNota.getSelectedItem());//tipo_nf
                nf.setNaturaOpNotaFiscal((String) cbNaturezaOperacao.getSelectedItem());//natureza_op_nf
                nf.setDataSaidaNotaFiscal(sTxtDataSaidaEntrada.getText().trim());//data_saida_nf




                nf.setHoraSaidaNotaFiscal(sTxtHoraSaidaNotaFiscal.getText().trim());//hora_saida_nf
                nf.setServicoNotaFiscal(sTxtServicoNotaFiscal.getText().trim().toUpperCase());//servico_nf
                nf.setValorServico(Double.parseDouble(txtValorServicoNotaFiscal.getText().trim()));//valor_serv_nf
                double serv = 0;
                if (txtValorServicoNotaFiscal.getText().length() > 0) {
                    serv = Double.parseDouble(txtValorServicoNotaFiscal.getText().trim());
                    nf.setValorServico(Double.parseDouble(txtValorServicoNotaFiscal.getText().trim()));//valor_serv_nf
                } else {
                    nf.setValorServico(serv);
                }
                totalNf = totalNf + serv;
                nf.setValorTotalNotaFiscal(totalNf);//valor_tot_nf
                if (opc == 1) {
                    String sql = "UPDATE NOTA_FISCAL SET data_nf=TO_DATE('" + nf.getDataNotaFiscal() + "','DD/MM/YYYY'), valor_tot_nf=?              ,observacao_nf=?              ,tipo_nf=?              ,natureza_op_nf=?           ,data_saida_nf=TO_DATE('" + nf.getDataSaidaNotaFiscal() + "','DD/MM/YYYY'),id_cliente=?      ,hora_saida_nf=?             ,servico_nf=?               ,valor_serv_nf=? , ID_CLIENTE_PJ=null,ID_FORNECEDOR=null where ID_NF=?";
                    Object[] parametros = {nf.getValorTotalNotaFiscal(), nf.getObservacaoNotaFiscal(), nf.getTipoNotaFiscal(), nf.getNaturaOpNotaFiscal(), cli.getIdCliente(), nf.getHoraSaidaNotaFiscal(), nf.getServicoNotaFiscal(), nf.getValorServico(), nf.getIdNotaFiscal()};
                    Object[] tipos = {Double.class, String.class, String.class, String.class, Integer.class, String.class, String.class, Double.class, Integer.class};

                    BD banco = new BD();

                    banco.executar(sql, parametros, tipos);
                    JOptionPane.showMessageDialog(rootPane, "Atualização realizada com sucesso");
                } else if (opc == 2) {
                    String sql = "UPDATE NOTA_FISCAL SET data_nf=TO_DATE('" + nf.getDataNotaFiscal() + "','DD/MM/YYYY'), valor_tot_nf=?              ,observacao_nf=?              ,tipo_nf=?              ,natureza_op_nf=?           ,data_saida_nf=TO_DATE('" + nf.getDataSaidaNotaFiscal() + "','DD/MM/YYYY'),id_cliente_PJ=?      ,hora_saida_nf=?             ,servico_nf=?               ,valor_serv_nf=?, ID_CLIENTE=null,ID_FORNECEDOR=null WHERE ID_NF=?";
                    Object[] parametros = {nf.getValorTotalNotaFiscal(), nf.getObservacaoNotaFiscal(), nf.getTipoNotaFiscal(), nf.getNaturaOpNotaFiscal(), clipj.getIdClientePJ(), nf.getHoraSaidaNotaFiscal(), nf.getServicoNotaFiscal(), nf.getValorServico(), nf.getIdNotaFiscal()};
                    Object[] tipos = {Double.class, String.class, String.class, String.class, Integer.class, String.class, String.class, Double.class, Integer.class};

                    BD banco = new BD();

                    banco.executar(sql, parametros, tipos);
                    JOptionPane.showMessageDialog(rootPane, "Atualização realizada com sucesso");
                } else if (opc == 3) {
                    String sql = "UPDATE NOTA_FISCAL SET data_nf=TO_DATE('" + nf.getDataNotaFiscal() + "','DD/MM/YYYY'), valor_tot_nf=?              ,observacao_nf=?              ,tipo_nf=?              ,natureza_op_nf=?           ,data_saida_nf=TO_DATE('" + nf.getDataSaidaNotaFiscal() + "','DD/MM/YYYY'),ID_FORNECEDOR=?      ,hora_saida_nf=?             ,servico_nf=?               ,valor_serv_nf=?,ID_CLIENTE=null,ID_CLIENTE_PJ=null  WHERE ID_NF=?";
                    Object[] parametros = {nf.getValorTotalNotaFiscal(), nf.getObservacaoNotaFiscal(), nf.getTipoNotaFiscal(), nf.getNaturaOpNotaFiscal(), forn.getIdFornecedor(), nf.getHoraSaidaNotaFiscal(), nf.getServicoNotaFiscal(), nf.getValorServico(), nf.getIdNotaFiscal()};
                    Object[] tipos = {Double.class, String.class, String.class, String.class, Integer.class, String.class, String.class, Double.class, Integer.class};

                    BD banco = new BD();

                    banco.executar(sql, parametros, tipos);
                    JOptionPane.showMessageDialog(rootPane, "Atualização realizada com sucesso");
                }


            } catch (Exception ex) {
                Logger.getLogger(EditarNotaFiscal.class.getName()).log(Level.SEVERE, null, ex);
            }
/////////////////////////////////FIM DE SALVANDO A NOTA//////////////////////////////////////////////////////////


            try {
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                String del = "DELETE FROM NOTA_HAS_PECA WHERE ID_NF=?";
                BD banco2 = new BD();
                Object[] parametros2 = {nf.getIdNotaFiscal()};
                Object[] tipos2 = {Integer.class};
                banco2.executar(del, parametros2, tipos2);
//////////////////////////////////////////////////////////////////////////////////////////////////////////
                DefaultTableModel tableModel = (DefaultTableModel) tabelaPecas.getModel();
                int linhas = tableModel.getRowCount();//contando quantas colunas tem
                int i = 0;
                if (linhas > 0) {
                    while (i < linhas) {
                        NotaHasPeca ntPc = new NotaHasPeca();

                        ntPc.setValorUnitPeca(Double.parseDouble(tableModel.getValueAt(i, 4).toString()));
                        ntPc.setValorTotPeca(Double.parseDouble(tableModel.getValueAt(i, 5).toString()));
                        ntPc.setQuantPeca(Double.parseDouble(tableModel.getValueAt(i, 3).toString()));
                        ntPc.setUnidadePeca(tableModel.getValueAt(i, 2).toString().toUpperCase());


                        Peca Pc = new Peca();

                        Pc.setIdPeca(Integer.parseInt(tableModel.getValueAt(i, 0).toString().toUpperCase()));

                        String sql = "INSERT INTO NOTA_HAS_PECA (ID_NT_PECA              ,VALOR_UN_PECA,VALOR_TOT_PECA,QUANT_PECA,UNID_PECA,ID_NF,ID_PECA)"
                                + "VALUES (SQ_NOTA_HAS_PECA.NEXTVAL,?            ,?             ,?         ,?        ,?    ,?      )";

                        Object[] parametros = {ntPc.getValorUnitPeca(), ntPc.getValorTotPeca(), ntPc.getQuantPeca(), ntPc.getUnidadePeca(), nf.getIdNotaFiscal(), Pc.getIdPeca()};
                        Object[] tipos = {Double.class, Double.class, Double.class, String.class, Integer.class, Integer.class};

                        BD banco = new BD();

                        banco.executar(sql, parametros, tipos);



                        i++;
                    }
                }
                /////////////////////////////////FIM DE PEGANDO A ULTIMA NOTA GERADA E SALVADO NA TABELA NOTA_HAS_PECA//////////
            } catch (Exception ex) {
                Logger.getLogger(EditarNotaFiscal.class.getName()).log(Level.SEVERE, null, ex);
            }


        }////////////////////FIM DO SE NOTA ENTRADA PESSOA FISICA////////////////////////////////////////////


    }//GEN-LAST:event_jButton3ActionPerformed

    private void btExcluirPecaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btExcluirPecaActionPerformed
        ((DefaultTableModel) tabelaPecas.getModel()).removeRow(tabelaPecas.getSelectedRow());
    }//GEN-LAST:event_btExcluirPecaActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        LocalizarClienteInserir locins = new LocalizarClienteInserir(3);
        locins.recebeEDnf(this);
        locins.setVisible(true);
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        LocalizarClienteJuridicoInserir locclipj = new LocalizarClienteJuridicoInserir(3);
        locclipj.recebeEDnf(this);
        locclipj.setVisible(true);
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        LocalizarFornecedorInseir locforn = new LocalizarFornecedorInseir();
        locforn.recebeEDnf(this);
        locforn.setVisible(true);
    }//GEN-LAST:event_jButton4ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new EditarNotaFiscal().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField TxtComplCliente;
    private javax.swing.JButton btExcluirPeca;
    private javax.swing.JButton btIncluirPeca;
    private javax.swing.JButton btLocPecaNF;
    private javax.swing.JButton btSairNotaFiscal;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JTextField cbBairroCliente;
    private javax.swing.JTextField cbCidadeCliente;
    private javax.swing.JComboBox cbNaturezaOperacao;
    private javax.swing.JComboBox cbTipoNota;
    private javax.swing.JTextField cbUfCliente;
    private javax.swing.JComboBox cbUniNF;
    private javax.swing.JTextField iTxtNumeroCliente;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTabbedPane jTabbedPaneNF;
    private javax.swing.JTextField jTextField35;
    private javax.swing.JLabel lblApSalaNotaFiscal;
    private javax.swing.JLabel lblBairroNotaFiscal;
    private javax.swing.JLabel lblCidadeNotaFiscal;
    private javax.swing.JLabel lblCnpjCpfNotaFiscal;
    private javax.swing.JLabel lblDataEmissaoNotaFiscal;
    private javax.swing.JLabel lblDataEntradaSaidaNotaFiscal;
    private javax.swing.JLabel lblHoraSaidaNotaFiscal;
    private javax.swing.JLabel lblIncricaoEstadualNotaFiscal;
    private javax.swing.JLabel lblNaturezaOperacaoNotaFiscal;
    private javax.swing.JLabel lblNomeRazaoNotaFiscal;
    private javax.swing.JLabel lblNumeroNotaFiscal;
    private javax.swing.JLabel lblRuaAvenidaNotaFiscal;
    private javax.swing.JLabel lblTelefoneFaxNotaFiscal;
    private javax.swing.JLabel lblUfNotaFiscal;
    private javax.swing.JLabel lblValorServicoNotaFiscal;
    private javax.swing.JPanel pnlCadastroNotaFiscal;
    private javax.swing.JPanel pnlDestinatarioRemetente;
    private javax.swing.JPanel pnlDestinatarioRemetenteNotaFiscal;
    private javax.swing.JPanel pnlEnderecoNotaFiscal;
    private javax.swing.JPanel pnlInternoServiçoNota;
    private javax.swing.JPanel pnlNaturezaOperacao;
    private javax.swing.JPanel pnlPecaNotaFilcal;
    private javax.swing.JPanel pnlProdutoPeca;
    private javax.swing.JPanel pnlServNotaFilcal;
    private javax.swing.JRadioButton rdPessoaFisicaNotaFiscal;
    private javax.swing.JRadioButton rdPessoaJuridicaNotaFiscal;
    private javax.swing.JFormattedTextField sTxtCnpjCpfNotaFiscal;
    private javax.swing.JFormattedTextField sTxtDataEmissao;
    private javax.swing.JFormattedTextField sTxtDataSaidaEntrada;
    private javax.swing.JFormattedTextField sTxtHoraSaidaNotaFiscal;
    private javax.swing.JTextField sTxtIncricaoEstadualNotaFiscal;
    private javax.swing.JTextField sTxtNomeRazaoSocialNotaFiscal;
    private javax.swing.JTextArea sTxtServicoNotaFiscal;
    private javax.swing.JTextField sTxtTelefoneFaxNotaFiscal;
    private javax.swing.JTextField stxtApSalaCliente;
    private javax.swing.JTextArea stxtAreaNotaFiscal;
    private javax.swing.JTextField stxtCEPCliente;
    private javax.swing.JTable tabelaPecas;
    private javax.swing.JTextField txtCodPeca;
    private javax.swing.JTextField txtEndCliente;
    private javax.swing.JTextField txtQuantNF;
    private javax.swing.JTextField txtValorServicoNotaFiscal;
    private javax.swing.JTextField txtValorUnitNF;
    // End of variables declaration//GEN-END:variables

    public void preenchePf(Cliente cliente) {
        this.cli = cliente;
        opc = 1;
        rdPessoaFisicaNotaFiscal.setSelected(true);
        sTxtNomeRazaoSocialNotaFiscal.setText(cliente.getNomePessoa());
        sTxtCnpjCpfNotaFiscal.setText(cliente.getCpfPessoa());
        sTxtIncricaoEstadualNotaFiscal.setText("Isento");
        sTxtTelefoneFaxNotaFiscal.setText(cliente.getTelPessoa());
        cbUfCliente.setText(cliente.getEnd().getBairroEndereco().getCidadeBairro().getEstadoCidade().getIdUf());
        cbCidadeCliente.setText(cliente.getEnd().getBairroEndereco().getCidadeBairro().getNomeCidade());
        cbBairroCliente.setText(cliente.getEnd().getBairroEndereco().getNomeBairro());
        stxtCEPCliente.setText(cliente.getEnd().getCepEndereco());
        txtEndCliente.setText(cliente.getEnd().getNomeEndereco());
        TxtComplCliente.setText(cliente.getComplementoPessoa());
        iTxtNumeroCliente.setText("" + cliente.getNumPessoa());
        stxtApSalaCliente.setText(cliente.getApartPessoa());
    }

    public void preenchePJ(ClientePJ clientePJ) {
        opc = 2;
        this.clipj = clientePJ;
        rdPessoaJuridicaNotaFiscal.setSelected(true);
        rdPessoaFisicaNotaFiscal.setSelected(false);
        sTxtNomeRazaoSocialNotaFiscal.setText(clientePJ.getRazaoSocialFornecedor());
        sTxtCnpjCpfNotaFiscal.setText(clientePJ.getCnpjFornecedor());
        sTxtIncricaoEstadualNotaFiscal.setText(clientePJ.getInscEstadualFornecedor());
        sTxtTelefoneFaxNotaFiscal.setText(clientePJ.getTelFornecedor());
        cbUfCliente.setText(clientePJ.getEndereco().getBairroEndereco().getCidadeBairro().getEstadoCidade().getIdUf());
        cbCidadeCliente.setText(clientePJ.getEndereco().getBairroEndereco().getCidadeBairro().getNomeCidade());
        cbBairroCliente.setText(clientePJ.getEndereco().getBairroEndereco().getNomeBairro());
        stxtCEPCliente.setText(clientePJ.getEndereco().getCepEndereco());
        txtEndCliente.setText(clientePJ.getEndereco().getNomeEndereco());
        TxtComplCliente.setText(clientePJ.getComplementoFornecedor());
        iTxtNumeroCliente.setText("" + clientePJ.getNumFornecedor());
        stxtApSalaCliente.setText(clientePJ.getSalaFornecedor());
    }

    public void iniciar() {
        rdPessoaJuridicaNotaFiscal.setEnabled(false);
        rdPessoaFisicaNotaFiscal.setEnabled(false);
        sTxtNomeRazaoSocialNotaFiscal.setEnabled(false);
        sTxtCnpjCpfNotaFiscal.setEnabled(false);
        sTxtIncricaoEstadualNotaFiscal.setEnabled(false);
        sTxtTelefoneFaxNotaFiscal.setEnabled(false);
        cbUfCliente.setEnabled(false);
        cbCidadeCliente.setEnabled(false);
        cbBairroCliente.setEnabled(false);
        stxtCEPCliente.setEnabled(false);
        txtEndCliente.setEnabled(false);
        TxtComplCliente.setEnabled(false);
        iTxtNumeroCliente.setEnabled(false);
        stxtApSalaCliente.setEnabled(false);
    }

    public void preencheFOR(Fornecedor fornecedor) {
        this.forn = fornecedor;
        opc = 3;
        rdPessoaJuridicaNotaFiscal.setSelected(true);
        rdPessoaFisicaNotaFiscal.setSelected(false);
        sTxtNomeRazaoSocialNotaFiscal.setText(fornecedor.getRazaoSocialFornecedor());
        sTxtCnpjCpfNotaFiscal.setText(fornecedor.getCnpjFornecedor());
        sTxtIncricaoEstadualNotaFiscal.setText(fornecedor.getInscEstadualFornecedor());
        sTxtTelefoneFaxNotaFiscal.setText(fornecedor.getTelFornecedor());
        cbUfCliente.setText(fornecedor.getEndereco().getBairroEndereco().getCidadeBairro().getEstadoCidade().getIdUf());
        cbCidadeCliente.setText(fornecedor.getEndereco().getBairroEndereco().getCidadeBairro().getNomeCidade());
        cbBairroCliente.setText(fornecedor.getEndereco().getBairroEndereco().getNomeBairro());
        stxtCEPCliente.setText(fornecedor.getEndereco().getCepEndereco());
        txtEndCliente.setText(fornecedor.getEndereco().getNomeEndereco());
        TxtComplCliente.setText(fornecedor.getComplementoFornecedor());
        iTxtNumeroCliente.setText("" + fornecedor.getNumFornecedor());
        stxtApSalaCliente.setText(fornecedor.getSalaFornecedor());
    }

    public void iniciar(int IDNF, int tipocli) {
        this.tipocliente = tipocli;
        nf.setIdNotaFiscal(IDNF);
        if (tipocliente == 1) {
            opc = 1;
            try {
                String sql = "SELECT O.TIPO_NF,O.NATUREZA_OP_NF,O.DATA_NF,O.DATA_SAIDA_NF,O.HORA_SAIDA_NF,CLI.ID_CLIENTE,CLI.NOME_CLIENTE, "
                        + "CLI.CPF_CLIENTE,CLI.TEL_CLIENTE,EST.ID_UF,CID.NOME_CIDADE,BAI.NOME_BAIRRO,ENDE.CEP AS CEP_END,ENDE.NOME_ENDERECO, "
                        + "CLI.COMPLEMENTO_CLIENTE,CLI.NUM_CLIENTE,CLI.APART_CLIENTE,O.SERVICO_NF,O.VALOR_SERV_NF,O.OBSERVACAO_NF "
                        + "FROM NOTA_FISCAL O "
                        + "INNER JOIN CLIENTE CLI ON O.ID_CLIENTE= CLI.ID_CLIENTE "
                        + "INNER JOIN ENDERECO ENDE ON CLI.ID_ENDERECO=ENDE.ID_ENDERECO "
                        + "INNER JOIN BAIRRO BAI ON BAI.ID_BAIRRO=ENDE.ID_BAIRRO "
                        + "INNER JOIN CIDADE CID ON BAI.ID_CIDADE=CID.ID_CIDADE "
                        + "INNER JOIN ESTADO EST ON EST.ID_UF=CID.ID_UF WHERE O.ID_NF=" + nf.getIdNotaFiscal();


                BD bd = new BD();

                ResultSet rs = bd.consultar(sql);

                if (rs.next()) {

                    String d = rs.getString("DATA_NF");
                    String[] data = d.split("-");
                    String dia = data[2].split(" ")[0];
                    String mes = data[1];
                    String ano = data[0];
                    String DataNf = dia + "/" + mes + "/" + ano;

                    String d1 = rs.getString("DATA_SAIDA_NF");
                    String[] data1 = d1.split("-");
                    String dia1 = data1[2].split(" ")[0];
                    String mes1 = data1[1];
                    String ano1 = data1[0];
                    String DataSaida = dia1 + "/" + mes1 + "/" + ano1;

                    cbTipoNota.setSelectedItem(rs.getString("TIPO_NF"));
                    cbNaturezaOperacao.setSelectedItem(rs.getString("NATUREZA_OP_NF"));
                    sTxtDataEmissao.setText(DataNf);
                    sTxtDataSaidaEntrada.setText(DataSaida);
                    sTxtHoraSaidaNotaFiscal.setText(rs.getString("HORA_SAIDA_NF"));
                    rdPessoaFisicaNotaFiscal.setSelected(true);


                    cli.setIdCliente(rs.getInt("ID_CLIENTE"));
                    sTxtNomeRazaoSocialNotaFiscal.setText(rs.getString("NOME_CLIENTE"));

                    sTxtCnpjCpfNotaFiscal.setText(rs.getString("CPF_CLIENTE"));

                    sTxtIncricaoEstadualNotaFiscal.setText("ISENTO");

                    sTxtTelefoneFaxNotaFiscal.setText(rs.getString("TEL_CLIENTE"));

                    cbUfCliente.setText(rs.getString("ID_UF"));

                    cbCidadeCliente.setText(rs.getString("NOME_CIDADE"));

                    cbBairroCliente.setText(rs.getString("NOME_BAIRRO"));

                    txtEndCliente.setText(rs.getString("NOME_ENDERECO"));

                    stxtCEPCliente.setText(rs.getString("CEP_END"));

                    TxtComplCliente.setText(rs.getString("COMPLEMENTO_CLIENTE"));

                    iTxtNumeroCliente.setText(rs.getString("NUM_CLIENTE"));

                    stxtApSalaCliente.setText(rs.getString("APART_CLIENTE"));

                    stxtAreaNotaFiscal.setText(rs.getString("OBSERVACAO_NF"));
                    sTxtServicoNotaFiscal.setText(rs.getString("SERVICO_NF"));
                    txtValorServicoNotaFiscal.setText(rs.getString("VALOR_SERV_NF"));

                }


            } catch (ClassNotFoundException ex) {
                Logger.getLogger(EditarNotaFiscal.class.getName()).log(Level.SEVERE, null, ex);
            } catch (SQLException ex) {
                Logger.getLogger(EditarNotaFiscal.class.getName()).log(Level.SEVERE, null, ex);
            }


            try {
                String sqlp = "SELECT NP.ID_PECA,PE.NOME_PECA,NP.UNID_PECA,NP.QUANT_PECA,NP.VALOR_UN_PECA,NP.VALOR_TOT_PECA "
                        + "FROM NOTA_HAS_PECA NP INNER JOIN PECA PE ON PE.ID_PECA=NP.ID_PECA "
                        + "WHERE NP.ID_NF=" + nf.getIdNotaFiscal();

                BD bd5 = new BD();
                ResultSet red;

                red = bd5.consultar(sqlp);
                DefaultTableModel model = (DefaultTableModel) tabelaPecas.getModel();

                while (red.next()) {
                    Object[] linha = {
                        red.getInt("ID_PECA"),
                        red.getString("NOME_PECA"),
                        red.getString("UNID_PECA"),
                        red.getDouble("QUANT_PECA"),
                        red.getDouble("VALOR_UN_PECA"),
                        red.getDouble("VALOR_TOT_PECA")
                    };

                    model.addRow(linha);

                }

            } catch (ClassNotFoundException ex) {
                Logger.getLogger(EditarNotaFiscal.class.getName()).log(Level.SEVERE, null, ex);
            } catch (SQLException ex) {
                Logger.getLogger(EditarNotaFiscal.class.getName()).log(Level.SEVERE, null, ex);
            }



            this.setVisible(true);
        } else if (tipocliente == 2) {
            opc = 2;
            try {
                String sql = "SELECT O.TIPO_NF,O.NATUREZA_OP_NF,O.DATA_NF,O.DATA_SAIDA_NF,O.HORA_SAIDA_NF,CLI.ID_CLIENTE_PJ, "
                        + "CLI.RAZAO_CLIENTE_PJ, CLI.CNPJ_CLIENTE_PJ,CLI.INSC_EST_CLIENTE_PJ,CLI.TEL_CLIENTE_PJ,EST.ID_UF,CID.NOME_CIDADE, "
                        + "BAI.NOME_BAIRRO,ENDE.CEP AS CEP_END,ENDE.NOME_ENDERECO,CLI.COMPL_CLIENTE_PJ, "
                        + "CLI.NUM_CLIENTE_PJ,CLI.SALA_CLIENTE_PJ,O.SERVICO_NF,O.VALOR_SERV_NF,O.OBSERVACAO_NF "
                        + "FROM NOTA_FISCAL O "
                        + "INNER JOIN CLIENTE_PJ CLI ON O.ID_CLIENTE_PJ= CLI.ID_CLIENTE_PJ "
                        + "INNER JOIN ENDERECO ENDE ON CLI.ID_ENDERECO=ENDE.ID_ENDERECO "
                        + "INNER JOIN BAIRRO BAI ON BAI.ID_BAIRRO=ENDE.ID_BAIRRO "
                        + "INNER JOIN CIDADE CID ON BAI.ID_CIDADE=CID.ID_CIDADE "
                        + "INNER JOIN ESTADO EST ON EST.ID_UF=CID.ID_UF WHERE O.ID_NF=" + nf.getIdNotaFiscal();

                BD bd = new BD();
                ResultSet rs = bd.consultar(sql);

                if (rs.next()) {

                    String d = rs.getString("DATA_NF");
                    String[] data = d.split("-");
                    String dia = data[2].split(" ")[0];
                    String mes = data[1];
                    String ano = data[0];
                    String DataNf = dia + "/" + mes + "/" + ano;

                    String d1 = rs.getString("DATA_SAIDA_NF");
                    String[] data1 = d1.split("-");
                    String dia1 = data1[2].split(" ")[0];
                    String mes1 = data1[1];
                    String ano1 = data1[0];
                    String DataSaida = dia1 + "/" + mes1 + "/" + ano1;

                    cbTipoNota.setSelectedItem(rs.getString("TIPO_NF"));
                    cbNaturezaOperacao.setSelectedItem(rs.getString("NATUREZA_OP_NF"));
                    sTxtDataEmissao.setText(DataNf);
                    sTxtDataSaidaEntrada.setText(DataSaida);
                    sTxtHoraSaidaNotaFiscal.setText(rs.getString("HORA_SAIDA_NF"));
                    rdPessoaJuridicaNotaFiscal.setSelected(true);


                    clipj.setIdClientePJ(rs.getInt("ID_CLIENTE_PJ"));
                    sTxtNomeRazaoSocialNotaFiscal.setText(rs.getString("RAZAO_CLIENTE_PJ"));

                    sTxtCnpjCpfNotaFiscal.setText(rs.getString("CNPJ_CLIENTE_PJ"));

                    sTxtIncricaoEstadualNotaFiscal.setText(rs.getString("INSC_EST_CLIENTE_PJ"));

                    sTxtTelefoneFaxNotaFiscal.setText(rs.getString("TEL_CLIENTE_PJ"));

                    cbUfCliente.setText(rs.getString("ID_UF"));

                    cbCidadeCliente.setText(rs.getString("NOME_CIDADE"));

                    cbBairroCliente.setText(rs.getString("NOME_BAIRRO"));

                    txtEndCliente.setText(rs.getString("NOME_ENDERECO"));

                    stxtCEPCliente.setText(rs.getString("CEP_END"));

                    TxtComplCliente.setText(rs.getString("COMPL_CLIENTE_PJ"));

                    iTxtNumeroCliente.setText(rs.getString("NUM_CLIENTE_PJ"));

                    stxtApSalaCliente.setText(rs.getString("SALA_CLIENTE_PJ"));//

                    stxtAreaNotaFiscal.setText(rs.getString("OBSERVACAO_NF"));
                    sTxtServicoNotaFiscal.setText(rs.getString("SERVICO_NF"));
                    txtValorServicoNotaFiscal.setText(rs.getString("VALOR_SERV_NF"));

                }


            } catch (ClassNotFoundException ex) {
                Logger.getLogger(EditarNotaFiscal.class.getName()).log(Level.SEVERE, null, ex);
            } catch (SQLException ex) {
                Logger.getLogger(EditarNotaFiscal.class.getName()).log(Level.SEVERE, null, ex);
            }


            try {

                String sqlp = "SELECT NP.ID_PECA,PE.NOME_PECA,NP.UNID_PECA,NP.QUANT_PECA,NP.VALOR_UN_PECA,NP.VALOR_TOT_PECA "
                        + "FROM NOTA_HAS_PECA NP INNER JOIN PECA PE ON PE.ID_PECA=NP.ID_PECA "
                        + "WHERE NP.ID_NF=" + nf.getIdNotaFiscal();

                BD bd5 = new BD();
                ResultSet red;

                red = bd5.consultar(sqlp);
                DefaultTableModel model = (DefaultTableModel) tabelaPecas.getModel();

                while (red.next()) {
                    Object[] linha = {
                        red.getInt("ID_PECA"),
                        red.getString("NOME_PECA"),
                        red.getString("UNID_PECA"),
                        red.getDouble("QUANT_PECA"),
                        red.getDouble("VALOR_UN_PECA"),
                        red.getDouble("VALOR_TOT_PECA")
                    };

                    model.addRow(linha);

                }

            } catch (ClassNotFoundException ex) {
                Logger.getLogger(EditarNotaFiscal.class.getName()).log(Level.SEVERE, null, ex);
            } catch (SQLException ex) {
                Logger.getLogger(EditarNotaFiscal.class.getName()).log(Level.SEVERE, null, ex);
            }



            this.setVisible(true);
        } else if (tipocliente == 3) {
            opc = 3;
            try {
                String sql = "SELECT O.TIPO_NF,O.NATUREZA_OP_NF,O.DATA_NF,O.DATA_SAIDA_NF,O.HORA_SAIDA_NF,FORN.ID_FORNECEDOR, "
                        + "FORN.RAZAO_FORNECEDOR, FORN.CNPJ_FORNECEDOR,FORN.INSC_EST_FORNECEDOR,FORN.TEL_FORNECEDOR,"
                        + "EST.ID_UF,CID.NOME_CIDADE, BAI.NOME_BAIRRO,ENDE.CEP AS CEP_END,ENDE.NOME_ENDERECO,"
                        + "FORN.COMP_FORNECEDOR, FORN.NUM_FORNECEDOR,FORN.SALA_FORNECEDOR,O.SERVICO_NF,O.VALOR_SERV_NF,"
                        + "O.OBSERVACAO_NF "
                        + "FROM NOTA_FISCAL O "
                        + "INNER JOIN FORNECEDOR FORN ON O.ID_FORNECEDOR= FORN.ID_FORNECEDOR "
                        + "INNER JOIN ENDERECO ENDE ON FORN.ID_ENDERECO=ENDE.ID_ENDERECO "
                        + "INNER JOIN BAIRRO BAI ON BAI.ID_BAIRRO=ENDE.ID_BAIRRO "
                        + "INNER JOIN CIDADE CID ON BAI.ID_CIDADE=CID.ID_CIDADE "
                        + "INNER JOIN ESTADO EST ON EST.ID_UF=CID.ID_UF WHERE O.ID_NF=" + nf.getIdNotaFiscal();

                BD bd = new BD();
                ResultSet rs = bd.consultar(sql);

                if (rs.next()) {

                    String d = rs.getString("DATA_NF");
                    String[] data = d.split("-");
                    String dia = data[2].split(" ")[0];
                    String mes = data[1];
                    String ano = data[0];
                    String DataNf = dia + "/" + mes + "/" + ano;

                    String d1 = rs.getString("DATA_SAIDA_NF");
                    String[] data1 = d1.split("-");
                    String dia1 = data1[2].split(" ")[0];
                    String mes1 = data1[1];
                    String ano1 = data1[0];
                    String DataSaida = dia1 + "/" + mes1 + "/" + ano1;

                    cbTipoNota.setSelectedItem(rs.getString("TIPO_NF"));
                    cbNaturezaOperacao.setSelectedItem(rs.getString("NATUREZA_OP_NF"));
                    sTxtDataEmissao.setText(DataNf);
                    sTxtDataSaidaEntrada.setText(DataSaida);
                    sTxtHoraSaidaNotaFiscal.setText(rs.getString("HORA_SAIDA_NF"));
                    rdPessoaJuridicaNotaFiscal.setSelected(true);


                    forn.setIdFornecedor(rs.getInt("ID_FORNECEDOR"));
                    sTxtNomeRazaoSocialNotaFiscal.setText(rs.getString("RAZAO_FORNECEDOR"));

                    sTxtCnpjCpfNotaFiscal.setText(rs.getString("CNPJ_FORNECEDOR"));

                    sTxtIncricaoEstadualNotaFiscal.setText(rs.getString("INSC_EST_FORNECEDOR"));

                    sTxtTelefoneFaxNotaFiscal.setText(rs.getString("TEL_FORNECEDOR"));

                    cbUfCliente.setText(rs.getString("ID_UF"));

                    cbCidadeCliente.setText(rs.getString("NOME_CIDADE"));

                    cbBairroCliente.setText(rs.getString("NOME_BAIRRO"));

                    txtEndCliente.setText(rs.getString("NOME_ENDERECO"));

                    stxtCEPCliente.setText(rs.getString("CEP_END"));

                    TxtComplCliente.setText(rs.getString("COMP_FORNECEDOR"));

                    iTxtNumeroCliente.setText(rs.getString("NUM_FORNECEDOR"));

                    stxtApSalaCliente.setText(rs.getString("SALA_FORNECEDOR"));//

                    stxtAreaNotaFiscal.setText(rs.getString("OBSERVACAO_NF"));

                    sTxtServicoNotaFiscal.setText(rs.getString("SERVICO_NF"));

                    txtValorServicoNotaFiscal.setText(rs.getString("VALOR_SERV_NF"));

                }


            } catch (ClassNotFoundException ex) {
                Logger.getLogger(EditarNotaFiscal.class.getName()).log(Level.SEVERE, null, ex);
            } catch (SQLException ex) {
                Logger.getLogger(EditarNotaFiscal.class.getName()).log(Level.SEVERE, null, ex);
            }


            try {
                String sqlp = "SELECT NP.ID_PECA,PE.NOME_PECA,NP.UNID_PECA,NP.QUANT_PECA,NP.VALOR_UN_PECA,NP.VALOR_TOT_PECA "
                        + "FROM NOTA_HAS_PECA NP INNER JOIN PECA PE ON PE.ID_PECA=NP.ID_PECA "
                        + "WHERE NP.ID_NF=" + nf.getIdNotaFiscal();

                BD bd5 = new BD();
                ResultSet red;

                red = bd5.consultar(sqlp);
                DefaultTableModel model = (DefaultTableModel) tabelaPecas.getModel();

                while (red.next()) {
                    Object[] linha = {
                        red.getInt("ID_PECA"),
                        red.getString("NOME_PECA"),
                        red.getString("UNID_PECA"),
                        red.getDouble("QUANT_PECA"),
                        red.getDouble("VALOR_UN_PECA"),
                        red.getDouble("VALOR_TOT_PECA")
                    };

                    model.addRow(linha);

                }

            } catch (ClassNotFoundException ex) {
                Logger.getLogger(EditarNotaFiscal.class.getName()).log(Level.SEVERE, null, ex);
            } catch (SQLException ex) {
                Logger.getLogger(EditarNotaFiscal.class.getName()).log(Level.SEVERE, null, ex);
            }



            this.setVisible(true);
        }
    }

    public boolean validar() {
        boolean Resultado = true;

        DefaultTableModel tableModel = (DefaultTableModel) tabelaPecas.getModel();
        int linhas = tableModel.getRowCount();//contando quantas colunas tem

        if (opc == 0) {
            JOptionPane.showMessageDialog(rootPane, "Obrigatória a seleção de um cliente ou Fornecedor!!!");
            Resultado = false;
        } else if (cbTipoNota.getSelectedItem().equals("ENTRADA") && cbNaturezaOperacao.getSelectedItem().equals("VENDA")) {
            JOptionPane.showMessageDialog(rootPane, "Tipo de Operação inválida para o Tipo de Nota!!!");
            Resultado = false;
        } else if (cbTipoNota.getSelectedItem().equals("SAIDA") && cbNaturezaOperacao.getSelectedItem().equals("COMPRA")) {
            JOptionPane.showMessageDialog(rootPane, "Tipo de Operação inválida para o Tipo de Nota!!!");
            Resultado = false;
        } else if (cbTipoNota.getSelectedItem().equals("")) {
            JOptionPane.showMessageDialog(rootPane, "Obrigatória a seleção do Tipo de Nota!!!");
            Resultado = false;
        } else if (cbNaturezaOperacao.getSelectedItem().equals("")) {
            JOptionPane.showMessageDialog(rootPane, "Obrigatória a seleção da Natureza da Operação!!!");
            Resultado = false;
        } else if (validarData(sTxtDataEmissao.getText().trim()) == false) {
            Resultado = false;
        } else if (validarData(sTxtDataSaidaEntrada.getText().trim()) == false) {
            Resultado = false;
        } else if (validarObservacao(stxtAreaNotaFiscal.getText().trim()) == false) {
            Resultado = false;
        } else if (validarServico(sTxtServicoNotaFiscal.getText().trim(), txtValorServicoNotaFiscal.getText().trim().length()) == false) {
            Resultado = false;

        } else if (validarValorServico(txtValorServicoNotaFiscal.getText().trim(), sTxtServicoNotaFiscal.getText().trim().length()) == false) {
            Resultado = false;
        } else if (linhas == 0 && txtValorServicoNotaFiscal.getText().trim().length() == 0) {
            Resultado = false;
            JOptionPane.showMessageDialog(rootPane, "Obrigatório o Preenchimento de uma Peça ou Serviço");
        }


        return Resultado;
    }

    public boolean validarPeca() {
        boolean Resultado = true;

        if (validarNumero(txtCodPeca.getText().trim()) == false) {
            Resultado = false;
        } else if (cbUniNF.getSelectedItem().equals("")) {
            JOptionPane.showMessageDialog(rootPane, "Seleção do campo Unidade Obrigatório!!");
            Resultado = false;
        } else if (validarQuant(txtQuantNF.getText().trim()) == false) {
            Resultado = false;
        } else if (validarValor(txtValorUnitNF.getText().trim()) == false) {
            Resultado = false;
        }

        return Resultado;
    }
}
